#ifndef __COMM_HPP__
#define __COMM_HPP__

#include <iostream>
#include <string>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <unistd.h>

using namespace std;

#define Mode 0666
#define Path "./fifo"

class Fifo
{
public:
	Fifo(const string &path) : _path(path)
	{
		umask(0);
		int n = mkfifo(_path.c_str(), Mode); // 创建命名管道，成功返回0，失败返回-1
		if (n == 0)
		{
			cout << "mkfifo success..." << endl;
		}
		else
		{
			cerr << "mkfifo failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
		}
	}
	~Fifo()
	{
		int n = unlink(_path.c_str());

		if (n == 0)
		{
			cout << "unlink success..." << endl;
		}
		else
		{
			cerr << "unlink failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
		}
	}

private:
	string _path; // 文件路劲+文件名
};

#endif